# import cv2 as cv
# import numpy as np
#
# def video_demo():
#     capture =cv.VideoCapture(0)
#     while(True):
#         ret,frame= capture.read()
#         cv.imshow("video",frame)
#         c =cv.waitKey(50)
#         if c==27:
#             break

#
# def get_image_info(image):
#     print(type(image))
#     print(image.shape)
#     print(image.size)
#     print(image.dtype)
#
#
# print("==========Hello Python========")
# src =cv.imread("C:/Users/asus/Pictures/Camera Roll/timg.jpg")
# cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)
# cv.imshow("input image",src)
# # get_image_info(src)
# video_demo()
# cv.waitKey(0)
# cv.destroyAllWindows()
#

# import random
# x=[]
# num =20
# while num>0:
#     y=random.randint(1, 40)
#     if y not in x:
#         x.append(y)
#         num -= 1
# x.sort()
# print(x)
#
#coding=utf-8
# 图片的写入
import cv2 as cv
img =cv.imread("C:\\Users\\asus\\Pictures\\Camera Roll\\111111.jpg",0)
# img1 =cv.putText(img,'lanyangyang', (30, 50), cv.FONT_HERSHEY_SIMPLEX, 1.2, (1, 3, 250), 2)
img =cv.resize(img,(200,200))
#关键的语句
print(cv.imwrite('C:\\Users\\asus\\Pictures\\Camera Roll\\111111.pgm',img))

# img =cv.imread('C:/Users/asus/Desktop/2.jpg')
# cv.imshow('my photo',img)
# cv.namedWindow('照片',10*10)
cv.waitKey()
cv.destroyAllWindows()

# import cv2 as cv
# img = cv.imread("C:/Users/asus/Pictures/Camera Roll/timg.jpg",1)
# font = cv.FONT_HERSHEY_SIMPLEX
# #图片添加文字
# imgzi = cv.putText(img, 'lanyangyang', (30, 50), font, 1.2, (1, 3, 250), 2)
# cv.imshow('111',img)


# 摄像头的打开
# import cv2 as cv
# import numpy as np
# capture = cv.VideoCapture(0)
# while True:
#     ret, frame = capture.read()
#     gray_img =cv.cvtColor(frame,cv.COLOR_BGR2GRAY)
#     # cv.imshow("video", gray_img)#设置黑白
#     cv.imshow('video',frame)
#     c = cv.waitKey(50)
# cv.waitKey()
# cv.destroyAllWindows()
# capture = cv.VideoCapture(0)

# 视频的读取
# import cv2 as cv
# img = cv.VideoCapture('C:\\Users\\asus\\Desktop\\666.mp4')
# while img.isOpened():
#     ret,frame =img.read()
#     #显示图片大小调整
#     cv.namedWindow('vidoe', 0)
#     cv.imshow('vidoe',frame)
#     cv.waitKey(100)
# img.release()
# cv.destroyAllWindows()

# import cv2 as cv
# img = cv.VideoCapture('C:\\Users\\asus\\Desktop\\666.mp4')
# i=1
# while True:
#     ret,frame =img.read()
#     if ret ==False:
#         break

    #显示图片大小调整
    # cv.namedWindow('vidoe', 0)
    # cv.imshow('vidoe',frame)
    # str1 ='C:\\Users\\asus\\Pictures\\Camera Roll\\picture\\'+str(i)+'.jpg'
    # i+=1
    # cv.imwrite(str1,frame)
    # cv.waitKey(100)
# img.release()
# cv.destroyAllWindows()
import cv2 as cv
import numpy as np
from numpy.core._multiarray_umath import ndarray

#
# def access_pixels(img):
#     print(img.shape) #取图像的长、宽和颜色
#     hight = img.shape[0] #取图像的长
#     width = img.shape[1] #取图像的宽
#     chanmels = img.shape[2] #取图像的颜色通道
#     for row in range(hight):
#         for col in range(width):
#             for c in range(chanmels):
#                 pv = img[row, col, c]
#                 img[row, col, c] = 255 - pv
#     cv.imshow("pixels_demo", img)
#
# def inverse(image):
#     dst =cv.bitwise_not(image)
#     cv.imshow('inverse demo',dst)

# def create_image():
    # img = np.zeros([400,400,3],np.uint8)
    # img[ : , : ,0] =np.ones([400,400])*255
    # cv.imshow('ner image',img)
    #
    # img =np.ones([400,400,1],np.uint8)
    # img =img *0
    # cv.imshow('new img',img)
    # cv.imwrite('D:/myimage.png',img)

    # m1 = np.ones([3,3],np.uint8)
    # m1.fill(122.388)
    # print(m1)
    # m2 =m1.reshape([1,9])  #reshape([几行,几列])降低数组的维度
    # print(m2)
#
# '''
#     色彩空间转换API：
#         常见色彩空间：RGB、HSV、HIS、YCrCb、YUV
#         最常见有两个HSV和RGB、YUV与RGB
#     学会是用inRange
#
# '''
# def color_space_demo(image):
#     gray =cv.cvtColor(image,cv.COLOR_BGR2GRAY)
#     cv.imshow('gray',gray)
#     hsv = cv.cvtColor(image, cv.COLOR_BGR2HSV)
#     cv.imshow('hsv', hsv)
#     yuv = cv.cvtColor(image, cv.COLOR_BGR2YUV)
#     cv.imshow('yuv', yuv)
#     YCrCb = cv.cvtColor(image, cv.COLOR_BGR2YCrCb)
#     cv.imshow('YCrCb', YCrCb)
#
#
# '''
#     np.array() #建立一个数组
#     a3.fill(8)  #数组铺满8
# '''
# img = cv.imread("C:/Users/asus/Pictures/Camera Roll/timg.jpg",1)
# cv.namedWindow('input img',cv.WINDOW_AUTOSIZE)
# cv.imshow('input img',img)
# t1 =cv.getTickCount() #获取按键时间
# # access_pixels(img)
# color_space_demo(img)#色彩空间
# inverse(img)
# # create_image()
# t2 =cv.getTickCount()
# print('time:',(t2-t1)/cv.getTickFrequency())
# # a3 =np.array([[2,3,4],[4,5,6],[7,8,9]],np.int32)  #建立一个数组
# # a3.fill(8)  #数组铺满8
# # print(a3)
# cv.waitKey(0)

# import cv2 as cv
# import numpy as np
# img =np.zeros((400,400),dtype=np.uint8)
# img2 =150-img
# cv.imshow('test',img2)
# print(img.shape)
# cv.waitKey(0)

